﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Plane
{
    public partial class Rank : Form
    {
        private MainWindow main;
        public Rank(MainWindow main)
        {
            InitializeComponent();
            // 在窗体加载时显示排行榜
            LoadRankings();
            this.main = main;
        }

        private void LoadRankings()
        {
            try
            {
                // 调用 UserDbHelper 类的 GetTopThreeScorers 方法获取前三名用户的数据
                List<(string Username, int HighestScore)> topScorers = UserDbHelper.GetTopThreeScorers();

                // 确保有足够的 TextBox 控件来显示数据
                TextBox[] usernameTextBoxes = { textBox6, textBox1, textBox3 };
                TextBox[] scoreTextBoxes = { textBox5, textBox2, textBox4 };

                // 遍历前三名用户的数据
                for (int i = 0; i < Math.Min(topScorers.Count, 3); i++)
                {
                    // 显示用户名
                    usernameTextBoxes[i].Text = topScorers[i].Username;
                    // 显示得分
                    scoreTextBoxes[i].Text = topScorers[i].HighestScore.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"加载排行榜失败: {ex.Message}");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            main.Show();
            this.Hide();
        }
    }
}
